var spuId = sessionStorage.getItem("spu_id");
var spuDetails=""//详情信息
/*详情查询*/
spuInfo()
function spuInfo() {
    $.ajax({
        type: "POST",
        url: root.goodsInter.goods_getSpuDetail,
        cache: false,  //禁用缓存
        dataType: "json",
        async:false,//优先运行
        data: {
            spuId: spuId
        },
        success: function (result) {
            if (result.errorCode == 0) {
                var spudata=result.spu
                if(spudata){
                    /*架构信息*/
                    $("#spu_code").html(spudata.spu_code)
                    $("#commodity_type").html(spudata.commodity_type)
                    $("#spu_name").html(spudata.spu_name)
                    $("#subtitile").html(spudata.subtitile)
                    $("#category_name").html(spudata.category_name)
                    $("#category_product_type").html(spudata.category_product_type)
                    $("#brand_name").html(spudata.brand_name)
                    $("#is_sales_multi_measurement").html(spudata.is_sales_multi_measurement)
                    $("#areaNames").html(spudata.areaNames)
                    /*基本管理信息*/
                    $("#management_model").html(spudata.management_model)
                    $("#packing_list").html(spudata.packing_list)
                    $("#stock_attribute").html(spudata.stock_attribute)
                    $("#cooperation_mode").html(spudata.cooperation_mode)
                    $("#price_management_cycle").html(spudata.price_management_cycle)
                    $("#grade_external_positioning").html(spudata.grade_external_positioning)
                    $("#grade_internal_positioning").html(spudata.grade_internal_positioning)
                    $("#distribution_center").html(spudata.distribution_center)
                    $("#is_seasonal_commodities").html(spudata.is_seasonal_commodities)
                    $("#stock_up_period").html(spudata.stock_up_period)
                    $("#off_shelf_period").html(spudata.off_shelf_period)
                    $("#value_hierarchy").html(spudata.value_hierarchy)
                    /*营销信息*/
                    var sale_platform=""
                    if(spudata.sale_platform==1){
                        sale_platform="签约平台"
                    }else if(spudata.sale_platform==2){
                        sale_platform="普通平台"
                    }else if(spudata.sale_platform==3){
                        sale_platform="普通平台、签约平台"
                    }
                    $("#sale_platform").html(sale_platform)
                    $("#price_attribute").html(spudata.price_attribute)

                }
                /*基本属性组*/
                var attribute=result.attribute
                var attributedata=""
                if(attribute){
                    for(var i=0;i<attribute.length;i++){
                        attributedata+=' <tr>\n' +
                            '                                <td class="col-4-1 text-l">\n' +
                            '                                    <div class="row ml-10" >\n' +
                            '                                        <label class="form-label f-l label-right w-100" style="width: 124px;">'+attribute[i].basic_attributes_name+'：</label>\n' +
                            '                                        <div class="formControls w-150 ml-10 lh-26" style="width: 480px">'+attribute[i].basic_attributes_value+'</div>\n' +
                            '                                    </div>\n' +
                            '                                </td>\n' +
                            '                            </tr>'
                    }


                }else {
                    attributedata+=' <tr>\n' +
                        '                                <td class="col-4-1 text-l">\n' +
                        '                                    <div class="row ml-10" >\n' +
                        '                                        <label class="form-label f-l label-right w-100" style="width: 124px;">属性名称：</label>\n' +
                        '                                        <div class="formControls w-150 ml-10 lh-26" style="width: 480px"></div>\n' +
                        '                                    </div>\n' +
                        '                                </td>\n' +
                        '                            </tr>'
                }
                $("#attribute").html(attributedata)
                /*图片信息*/
                var spu_img=result.spu_img
                var imgdatas=""
                if(spu_img){
                    for(var m=0;m<spu_img.length;m++){
                     imgdatas+='<img src='+spu_img[m].img_url+' class="ml-20" width="150" height="150">'
                    }
                    $("#spuImgs").html(imgdatas)
                }

                /*详情信息*/
                var spuDetail=result.spuDetail
                if(spuDetail){

                    spuDetails=spuDetail
                   /* 默认PC详情*/
                   /* for(var h=0;h<spuDetail.length;h++){
                        if(spuDetail[h].application_platform==1){
                            ue.ready(function() {
                                console.log(spuDetail[h].detail)
                                ue.setContent(spuDetail[h].detail);
                            });
                        }
                    }*/

                }


            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}

/*详情信息*/
function detailsAll(val) {
    if(val==1){
       /* PC*/
        $("#appdetails").removeAttr("style")
        $("#pcdetails").attr("style","color: #fff;background-color: #4A90E2;border-color: #4A90E2;")
        if(spuDetails!=""){
            for(var s=0;s<spuDetails.length;s++){
                if(spuDetails[s].application_platform==1){
                    if(spuDetails[s].detail!=null&&spuDetails[s].detail!=""){
                        ue.ready(function() {
                            ue.setContent(spuDetails[s].detail);
                        });
                    }else{
                        ue.ready(function() {
                            ue.setContent("");
                        });
                    }
                }
            }
        }

    }else  if(val==2){
        /* APP*/
        $("#pcdetails").removeAttr("style")
        $("#appdetails").attr("style","color: #fff;background-color: #4A90E2;border-color: #4A90E2;")
        if(spuDetails!=""){
            for(var s=0;s<spuDetails.length;s++){
                if(spuDetails[s].application_platform==2){
                    if(spuDetails[s].detail!=null&&spuDetails[s].detail!=""){
                        ue.ready(function() {
                            ue.setContent(spuDetails[s].detail);
                        });

                    }else{
                        ue.ready(function() {
                            ue.setContent("");
                        });
                    }

                }
            }
        }

    }
}



